package basicJava.generics.generics2;

import java.io.UnsupportedEncodingException;
import java.util.Iterator;

public class IterableFibonacci extends Fibonacci implements Iterable<Integer> {

	private int n;
	
	public IterableFibonacci(int count){
		n=count;
	}
	
	public Iterator<Integer> iterator(){
		return new Iterator<Integer>() {
			public boolean hasNext(){
				return n>0;
			}
			
			public Integer next(){
				n--;
				return IterableFibonacci.this.next();
			}
			
			public void remove(){
				try {
					throw new UnsupportedEncodingException();
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
	}
	
	public static void main(String[] args){
		for (int i :new IterableFibonacci(18)) {
			System.out.println(i);
		}
	}
}
